package com.javaee.weixin.xiaochengxu.dto;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.javaee.weixin.xiaochengxu.tools.MD5Util;


@JsonInclude(value = Include.NON_EMPTY)
@JacksonXmlRootElement(localName = "xml")
public class UnifiedorderDto implements Serializable {

	String appid;
	@JacksonXmlProperty(localName = "mch_id")
	String mchId;
	@JacksonXmlProperty(localName = "device_info")
	String deviceInfo;
	@JacksonXmlProperty(localName = "nonce_str")
	String nonceStr;
	String sign;
	@JacksonXmlProperty(localName = "sign_type")
	String signType = "MD5";
	String body;
	@JacksonXmlCData
	String detail;
	String attach;
	@JacksonXmlProperty(localName = "out_trade_no")
	String outTradeNo;
	@JacksonXmlProperty(localName = "fee_type")
	String feeType;
	@JacksonXmlProperty(localName = "total_fee")
	double totalFee;
	@JacksonXmlProperty(localName = "spbill_create_ip")
	String spbillCreateIp;
	@JacksonXmlProperty(localName = "time_start")
	String timeStart;
	@JacksonXmlProperty(localName = "time_expire")
	String timeExpire;
	@JacksonXmlProperty(localName = "goods_tag")
	String goodsTag;
	@JacksonXmlProperty(localName = "notify_url")
	String notifyUrl;
	@JacksonXmlProperty(localName = "trade_type")
	String tradeType = "JSAPI";
	@JacksonXmlProperty(localName = "product_id")
	String productId;
	@JacksonXmlProperty(localName = "limit_pay")
	String limitPay;
	String openid;
	public void setSign(String key) {
		StringBuilder sb = new StringBuilder();
		if (StringUtils.isNotBlank(this.appid)) {
			sb.append("appid=" + this.appid);
		}
		if (StringUtils.isNotBlank(this.attach)) {
			sb.append("&attach=" + this.attach);
		}
		if (StringUtils.isNotBlank(this.body)) {
			sb.append("&body=" + this.body);
		}
		if (StringUtils.isNotBlank(this.detail)) {
			sb.append("&detail=" + this.detail);
		}
		if (StringUtils.isNotBlank(this.deviceInfo)) {
			sb.append("&device_info=" + this.deviceInfo);
		}
		if (StringUtils.isNotBlank(this.feeType)) {
			sb.append("&fee_type=" + this.feeType);
		}
		if (StringUtils.isNotBlank(this.goodsTag)) {
			sb.append("&goods_tag=" + this.goodsTag);
		}
		if (StringUtils.isNotBlank(this.limitPay)) {
			sb.append("&limit_pay=" + this.limitPay);
		}
		if (StringUtils.isNotBlank(this.mchId)) {
			sb.append("&mch_id=" + this.mchId);
		}
		if (StringUtils.isNotBlank(this.nonceStr)) {
			sb.append("&nonce_str=" + this.nonceStr);
		}
		if (StringUtils.isNotBlank(this.notifyUrl)) {
			sb.append("&notify_url=" + this.notifyUrl);
		}
		if (StringUtils.isNotBlank(this.openid)) {
			sb.append("&openid=" + this.getOpenid());
		}
		if (StringUtils.isNotBlank(this.outTradeNo)) {
			sb.append("&out_trade_no=" + this.outTradeNo);
		}
		if (StringUtils.isNotBlank(this.productId)) {
			sb.append("&product_id=" + this.productId);
		}
		if (StringUtils.isNotBlank(this.signType)) {
			sb.append("&sign_type=" + this.signType);
		}
		if (StringUtils.isNotBlank(this.spbillCreateIp)) {
			sb.append("&spbill_create_ip=" + this.spbillCreateIp);
		}

		if (StringUtils.isNotBlank(this.timeExpire)) {
			sb.append("&time_expire=" + this.timeExpire);
		}
		if (StringUtils.isNotBlank(this.timeStart)) {
			sb.append("&time_start=" + timeStart);
		}
		if (StringUtils.isNotBlank(this.getTotalFee())) {
			sb.append("&total_fee=" + this.getTotalFee());
		}
		if (StringUtils.isNotBlank(this.tradeType)) {
			sb.append("&trade_type=" + this.tradeType);
		}
		sb.append("&key=" + key);

		this.sign = MD5Util.getInstance().compile(sb.toString()).toUpperCase();
	}
	public String getAppid() {
		return appid;
	}
	public void setAppid(String appid) {
		this.appid = appid;
	}
	public String getMchId() {
		return mchId;
	}
	public void setMchId(String mchId) {
		this.mchId = mchId;
	}
	public String getDeviceInfo() {
		return deviceInfo;
	}
	public void setDeviceInfo(String deviceInfo) {
		this.deviceInfo = deviceInfo;
	}
	public String getNonceStr() {
		return nonceStr;
	}
	public void setNonceStr(String nonceStr) {
		this.nonceStr = nonceStr;
	}
	public String getSignType() {
		return signType;
	}
	public void setSignType(String signType) {
		this.signType = signType;
	}
	public String getBody() {
		return body;
	}
	public void setBody(String body) {
		this.body = body;
	}
	public String getDetail() {
		return detail;
	}
	public void setDetail(String detail) {
		this.detail = detail;
	}
	public String getAttach() {
		return attach;
	}
	//{am:0.0.1,b:'003}
	public void setAttach(String attach) {
		this.attach = attach;
	}
	public String getOutTradeNo() {
		return outTradeNo;
	}
	public void setOutTradeNo(String outTradeNo) {
		this.outTradeNo = outTradeNo;
	}
	public String getFeeType() {
		return feeType;
	}
	public void setFeeType(String feeType) {
		this.feeType = feeType;
	}
	public String getTotalFee() {
		DecimalFormat numberFormat = new DecimalFormat("#");
		return numberFormat.format(totalFee * 100);
	}
	public void setTotalFee(double totalFee) {
		this.totalFee = totalFee;
	}
	public String getSpbillCreateIp() {
		return spbillCreateIp;
	}
	public void setSpbillCreateIp(String spbillCreateIp) {
		this.spbillCreateIp = spbillCreateIp;
	}
	public String getTimeStart() {
		return timeStart;
	}
	public void setTimeStart(String timeStart) {
		this.timeStart = timeStart;
	}
	public String getTimeExpire() {
		return timeExpire;
	}
	public void setTimeExpire(String timeExpire) {
		this.timeExpire = timeExpire;
	}
	public String getGoodsTag() {
		return goodsTag;
	}
	public void setGoodsTag(String goodsTag) {
		this.goodsTag = goodsTag;
	}
	public String getNotifyUrl() {
		return notifyUrl;
	}
	public void setNotifyUrl(String notifyUrl) {
		this.notifyUrl = notifyUrl;
	}
	public String getTradeType() {
		return tradeType;
	}
	public void setTradeType(String tradeType) {
		this.tradeType = tradeType;
	}
	public String getProductId() {
		return productId;
	}
	public void setProductId(String productId) {
		this.productId = productId;
	}
	public String getLimitPay() {
		return limitPay;
	}
	public void setLimitPay(String limitPay) {
		this.limitPay = limitPay;
	}
	public String getOpenid() {
		return openid;
	}
	public void setOpenid(String openid) {
		this.openid = openid;
	}
	public String getSign() {
		return sign;
	}
}
